package ex03.connector.http;

/**
 * @packgeName: ex03.connector.http
 * @ClassName: HttpHeader
 * @copyright: CopyLeft
 * @description:<描述>
 * @author: lili
 * @date: 2017/8/11-18:52
 * @version: 1.0
 * @since: JDK 1.8
 */
final class HttpHeader {

    public static final int INITIAL_NAME_SIZE = 32;
    public static final int INTTIAL_VALUE_SIZE = 64;
    public static final int MAX_NAME_SIZE = 128;
    public static final int MAX_VALUE_SIZE = 4096;

    public char[] name;
    public int nameEnd;
    public char[] value;
    public int valueEnd;
    protected int hashCode = 0;

    public HttpHeader(){
        this(new char[INITIAL_NAME_SIZE],0,new char[INTTIAL_VALUE_SIZE],0);
    }

    public HttpHeader(String name, String value){
        //字符串转字符数组
        this.name = name.toLowerCase().toCharArray();
        this.nameEnd = name.length();
        this.value = value.toLowerCase().toCharArray();
        this.valueEnd = value.length();
    }

    public HttpHeader(char[] name, int nameEnd, char[] value, int valueEnd) {
        this.name = name;
        this.nameEnd = nameEnd;
        this.value = value;
        this.valueEnd = valueEnd;
    }

    public void recycle(){
        nameEnd = 0;
        valueEnd = 0;
        hashCode = 0;
    }
}
